package com.example.ch3_3.mapper;

import com.example.ch3_3.entity.Card;
import com.example.ch3_3.entity.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface StuMapper {
    @Select("select * from student where name like concat('%',#{name},'%')")
    List<Student> getStuByName(String name);
    @Result(property = "card",column = "no",one=@One(select = "com.example.ch3_3.mapper.StuMapper.getCardByNo"))
    @Select("select * from student where qq =#{qq}")
    List<Student> getStuByQQ(String qq);
    @Select("select * from card where cardNo=#{no}")
    Card getCardByNo(String no);
    @Select({
            "<script>",
            "select * from student",
            "<where>",
            "<if test='name != null'>",
            "and name=#{name}",
            "</if>",
            "<if test='no != null'>",
            "and no=#{no}",
            "</if>",
            "</where>",
            "</script>"
    })
    List<Student> getStuByNoOrName(String no, String name);
}
